package com.woniuxy.contract.controller;

import com.woniuxy.contract.service.ContractService;
import com.woniuxy.entity.ApprovalProcess;
import com.woniuxy.entity.Bank;
import com.woniuxy.entity.BorrowDemand;
import com.woniuxy.entity.Contract;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/contract")
public class ContractController {

    @Resource
    ContractService contractService;



    /*
    修改
     */
    @PutMapping("/update")
    public Contract updateContract(int id_contract) {


        Contract contract = contractService.updateContract(id_contract);


        return contract;
    }

    /*
    添加合同
     */
    @GetMapping("/add")
    public Contract addContract( Contract contract) {
        //调他们的方法获得参数

        BorrowDemand borrowDemand = new BorrowDemand();
        borrowDemand.setBorrow_money(500000);           //借款需求

        contract.setGuarantee("");          //担保物照片

        ApprovalProcess approvalProcess = new ApprovalProcess();//  流程表

        Bank bank = new Bank();
        bank.setAccount_num("123456789");   //设置银行卡账号

        contract.setContract_number("12345566");    //
        contract.setBorrow_id(borrowDemand.getBorrow_money());     //借款需求

        contract.setContract_number(UUID.randomUUID().toString());   //将合同编号变为uuid
        //contract.setEnterprise_id(allBusinessInfo.getData());        //企业信息
        contract.setRemit_id(Integer.parseInt(bank.getAccount_num()));         //银行卡账户
        contract.setGuarantee("");          //需要从远程得到图片
        contractService.addContract(contract);






        return contract;
    }

    /*
    查询所有合同
     */
    @GetMapping("/allContract")
    public List<Contract> selectAllContract(){

        List<Contract> contracts = contractService.selectAllContract();



        return contracts;
    }




}
